home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / JOHNLOVE / C_SOURCE / CMYMISC.C < prev    next >
Text File  |  1992-02-24  |  18KB  |  715 lines

  1. /*********************************************************
  2.  "CmyMisc.c"
  3.  
  4.  by John A. Love, III [Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.0.1
  7.  ... as derived from their "TCL Starter" files
  8.  *********************************************************/
  9.  
  10.  
  11.  
  12.  
  13. #include <CDesktop.h>
  14. #include <CDecorator.h>
  15. #include <CScrollPane.h>
  16. #include <CWindow.h>
  17. #include <OSChecks.h>
  18. #include <Sound.h>
  19. #include <Traps.h>
  20. #include <LongQD.h>
  21. #include <TCLUtilities.h>
  22.  
  23. #include "CmyGlobals.h"
  24. #include "CmyMisc.h"
  25.  
  26.  
  27. extern tSystem        gSystem;
  28. extern CDesktop        *gDesktop;
  29. extern CDecorator    *gDecorator;
  30.  
  31.  
  32.  
  33.  
  34. void    CSpiffyGraphics::ISystem7Braggart (CApplication *itsSupervisor)        {
  35. /* Note that we do NOT bother to pass a printable parm to this routine
  36. ** because we'll set it to false when we call IDocument.
  37. ** Print a splash screen -- you've got to be kidding ?!*!?              */
  38.  
  39.         short        kSystem7 = 777;
  40.  
  41.  
  42.  // TRY        --        TRY-CATCH-ENDTRY @ top of calling sequence.
  43.     {
  44.         CDocument::IDocument(itsSupervisor, false);
  45.         
  46.         itsWindow = new (CWindow);
  47.      /* FailNIL(itsWindow);   --   done by new() */
  48.         itsWindow->IWindow(kSystem7, false, gDesktop, this);
  49.      // Already centered by System 7:
  50.      // gDecorator->CenterWindow(itsWindow);
  51.     }
  52.         
  53.  /* CATCH
  54.     {
  55.         SysBeep(10);
  56.         SysBeep(10);
  57.         DisposeSystem7Braggart();
  58.     }
  59.         
  60.     ENDTRY;                            */
  61.  
  62. }    /* ISystem7Braggart */
  63.  
  64.  
  65.  
  66. void    CSpiffyGraphics::DisplaySystem7Braggart (void)    {
  67.  
  68.         Boolean            savedAlloc;
  69.         short            kSystem7 = 777;
  70.         Rect            wpRect, picRect;
  71.         PicHandle        myPic;
  72.         long            finalTicks;
  73.  
  74.  
  75.  // itsWindow->Select();  --  called by IWindow since WIND rsrc is visible.
  76.     itsWindow->Prepare();
  77.      
  78.      savedAlloc = SetAllocation(kAllocCanFail);
  79.     myPic = GetPicture(kSystem7);
  80.     SetAllocation(savedAlloc);
  81.     FailNILRes(myPic);
  82.  
  83.     /* If we've gotten this far, we have a pict: */
  84.     wpRect = itsWindow->macPort->portRect;
  85.     picRect = wpRect;
  86.     InsetRect(&picRect, 1, 1);
  87.     DrawPicture(myPic, &picRect);    //  ... so it's centered.
  88.     Delay(60, &finalTicks);
  89.     InvertRect(&wpRect);
  90.     Delay(120, &finalTicks);
  91.     ReleaseResource(myPic);
  92.  
  93. }    /* DisplaySystem7Braggart */
  94.  
  95.  
  96.  
  97. void    CSpiffyGraphics::DisposeSystem7Braggart (void)    {
  98.  
  99.  
  100.     inherited::Dispose();
  101.  
  102. }    /* DisposeSystem7Braggart */
  103.  
  104.  
  105.  
  106. void    CSpiffyGraphics::ISpiffyIris (CApplication *itsSupervisor)        {
  107.  
  108.         short            bragWindowID = 999;
  109.         Rect            bragRect;
  110.         LongRect        onScreen;
  111.         CmyBitMap        *braggart = NULL;
  112.  
  113.  
  114.     CDocument::IDocument(itsSupervisor, false);
  115.         
  116.     bragOSBMPane = nil;                // In case we bomb early ...
  117.     centeredPic = nil;
  118.         
  119.     itsWindow = new (CWindow);
  120.     itsWindow->IWindow(bragWindowID, false, gDesktop, this);
  121.     
  122.     /* -------------------------------------------------------
  123.     ** We will be placing a PICTure into an off screen BitMap.
  124.     ** If itsBitMap = NULL, then ImyBitMapPane calls:
  125.     **        new (CmyBitMap)
  126.     **        IBitMap and
  127.     **        itsBitMap->SetBoundsOrigin(...)
  128.     ** ------------------------------------------------------- */
  129.     
  130.     bragRect = itsWindow->macPort->portRect;
  131.     QDToLongRect(&bragRect, &onScreen);
  132.  
  133.     bragOSBMPane = new (CmyBitMapPane);
  134.     bragOSBMPane->itsBitMap = braggart;
  135.     bragOSBMPane->ImyBitMapPane(
  136.                                 itsWindow,        /* = itsEnclosure (CView)    */
  137.                                 this,            /* = CBureaucrat = this doc    */
  138.                                 0, 0, 0, 0,
  139.                                 sizELASTIC, sizELASTIC,
  140.                                 &onScreen,
  141.                                 braggart,
  142.                                 true            /* makePort */
  143.                              );
  144.     itsMainPane = bragOSBMPane;            /* CDocument instance variable. */
  145.     bragOSBMPane->FitToEnclosure(true, true);
  146.  
  147.     /* System 7 WIND resource automatically centers: */
  148.     if ( !WINDResourceHasSystem7Field(itsWindow) )        {
  149.         
  150.             short    saveProcID = itsWindow->procID;
  151.                 
  152.                 
  153.         itsWindow->SetModal(false);
  154.         // Gotta do this kludge because CenterWindow tests isModal
  155.         // AND the window's procID:
  156.         itsWindow->procID = 0;
  157.         gDecorator->CenterWindow(itsWindow);
  158.         itsWindow->procID = saveProcID;
  159.     }
  160.  
  161. }    /* ISpiffyIris */
  162.  
  163.  
  164.  
  165. void    CSpiffyGraphics::DisplaySpiffyIris (void)    {
  166.  
  167.         Boolean            savedAlloc;
  168.         CmyBitMap        *myBitMap;
  169.         short            IACS = 3001;
  170.         PicHandle        logoPicHdl;
  171.         short            maskPercent;
  172.         RgnHandle        irisRgn;
  173.         long            finalTicks, tempX, tempY;
  174.         Rect            pictRect, bragRect, tempShortR;
  175.         LongRect        offScreen, onScreen, tempLongR, irisRect;
  176.  
  177.  
  178.     itsWindow->Select();
  179.     itsMainPane->Prepare();
  180.      
  181.      savedAlloc = SetAllocation(kAllocCanFail);
  182.      logoPicHdl = GetPicture(IACS);
  183.     SetAllocation(savedAlloc);
  184.     FailNILRes(logoPicHdl);
  185.     
  186.     bragRect = itsWindow->macPort->portRect;
  187.  
  188.     pictRect = (**logoPicHdl).picFrame;        // Center the PICT ...
  189.     CenterRects(&pictRect, &bragRect);
  190.     
  191.     // Make a new PICT, this one centered & clipped to my portRect:
  192.     ClipRect(&bragRect);
  193.     centeredPic = OpenPicture(&bragRect);
  194.     ClipRect(&bragRect);
  195.     EraseRect(&bragRect);
  196.     InvertRect(&bragRect);
  197.     DrawPicture(logoPicHdl, &pictRect);
  198.     ClosePicture();
  199.     ;
  200.     MoveHHi(centeredPic);
  201.     HLock(centeredPic);
  202.     ReleaseResource(logoPicHdl);            /* Kiss the original good-bye !! */
  203.  
  204.     myBitMap = (CmyBitMap*) bragOSBMPane->GetBitMap();
  205.     myBitMap->GetBounds(&offScreen);            /* = local screen coordinates */
  206.     
  207.     myBitMap->BeginDrawing();
  208.     LClipRect(&offScreen);                        /* Draw off-screen ... */
  209.     LEraseRect(&offScreen);                        /* Eliminate all stray matter. */
  210.     tempLongR = offScreen;
  211.     LongToQDRect(&tempLongR, &tempShortR);
  212.     DrawPicture(centeredPic, &tempShortR);
  213.     myBitMap->EndDrawing();
  214.     
  215.  // bragRect = itsWindow->macPort->portRect;
  216.     QDToLongRect(&bragRect, &onScreen);
  217.  
  218.     LClipRect(&onScreen);
  219.  // LInvertRect(&onScreen);                        /* Part of centeredPic. */
  220.  
  221.     BackColor(whiteColor);
  222.     ForeColor(blackColor);
  223.     /* ---------- */
  224.     maskPercent = 99;                            /* Initialize some stuff ... */
  225.     tempX = (onScreen.right - onScreen.left) / 2;
  226.     tempY = (onScreen.bottom - onScreen.top) / 2;
  227.     myBitMap->SetXferMode(srcCopy);
  228.  
  229.     while (maskPercent >= 0)    {
  230.  
  231.         irisRect = onScreen;
  232.         InsetLongRect(&irisRect,
  233.                       (tempX * maskPercent) / 100,
  234.                       (tempY * maskPercent) / 100);
  235.         irisRgn = NewRgn();
  236.         OpenRgn();
  237.         {
  238.             LFrameRoundRect(
  239.                             &irisRect,
  240.                             ((irisRect.right - irisRect.left) * maskPercent) / 100,         
  241.                             ((irisRect.bottom - irisRect.top) * maskPercent) / 100
  242.                            );
  243.         }
  244.         CloseRgn(irisRgn);
  245.  
  246.         SectRgn(irisRgn, myBitMap->savePort->visRgn, irisRgn);
  247.         myBitMap->CopyFrom(&offScreen, &onScreen, irisRgn);
  248.  
  249.         DisposeRgn(irisRgn);
  250.         ;
  251.         if (gSystem.hasColorQD)        Delay(3, &finalTicks);
  252.         else                        Delay(1, &finalTicks);
  253.         ;
  254.         maskPercent--;
  255.     }    /* while maskPercent >= 0 */
  256.     /* ---------- */
  257.         
  258.     Delay(180, &finalTicks);        /* Take a gander at its beauty, folks !!! */
  259.  
  260. }    /* DisplaySpiffyIris */
  261.     
  262.  
  263.  
  264. void    CSpiffyGraphics::DisposeSpiffyIris (void)    {
  265.  
  266.  
  267.     if (centeredPic != nil)    {
  268.         HUnlock(centeredPic);
  269.         KillPicture(centeredPic);
  270.     }
  271.     
  272.     if (bragOSBMPane)        bragOSBMPane->Dispose();
  273.     inherited::Dispose();
  274.  
  275. }    /* DisposeSpiffyIris */
  276.  
  277.  
  278.  
  279. void    CSpiffyGraphics::ISpiffyScroll (CApplication *itsSupervisor)    {
  280.  
  281.         Boolean            savedAlloc;
  282.         short            kWAP = 3002, pScale = 12, saveProcID;
  283.         Str255            windTitle;
  284.      // CPicture        *pict;   --   in class description.
  285.         PicHandle        myPic;
  286.         CScrollPane        *scrollPn;
  287.         Rect            pictRect, paneRect;
  288.         
  289.         
  290.     CDocument::IDocument(itsSupervisor, false);
  291.     
  292.     /* I could later call CPicture::UsePICT, but I still need the PICT's
  293.     ** frame to dynamically alter the window size to accomodate the
  294.     ** PICT.  Since I need to call _GetPicture to retrieve this frame,
  295.     ** I finish off duplicating UsePICT by calling SetMacPicture below:    */
  296.      savedAlloc = SetAllocation(kAllocCanFail);
  297.     myPic = GetPicture(kWAP);
  298.     SetAllocation(savedAlloc);
  299.     FailNILRes(myPic);
  300.     
  301.     pictRect = (**myPic).picFrame;
  302.     
  303.     itsWindow = new (CWindow);
  304.     itsWindow->IWindow(kWAP, false, gDesktop, this);
  305.     itsWindow->GetTitle(windTitle);
  306.     
  307.     scrollPn = new (CScrollPane);
  308.     scrollPn->IScrollPane(itsWindow, this,        /* standard stuff ... */
  309.                           0, 0, 0, 0, sizELASTIC, sizELASTIC,
  310.                           false,                /* no horizontal scroll bar */
  311.                           false,                /* no vertical scroll bar */
  312.                           false                    /* no size box */    );
  313.     scrollPn->FitToEnclosure(true, true);
  314.     
  315.     pict = new (CPicture);
  316.     pict->IPicture(scrollPn, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
  317.     itsMainPane = pict;
  318.     itsGopher = pict;
  319.  
  320.     /* The enclosure will NOT include any of the Scroll Bars.
  321.     ** In this case, however, we stipulated there were none.  */
  322.     pict->FitToEnclosure(true, true);
  323.     pict->SetMacPicture(myPic);
  324.     
  325.     /* Stipulate that PICT will be drawn to original size,
  326.     ** NOT sized to fit the frame of the Scroll Pane:       */
  327.     pict->SetScaled(false);
  328.     pict->SetScales(pScale, pScale);
  329.     ;
  330.     scrollPn->InstallPanorama(pict);
  331.     
  332.     /* Alters the size of all sub-views which now include
  333.     ** the scroll pane and its associated panorama:          */
  334.     itsWindow->ChangeSize(
  335.             Max( 2*(pictRect.right - pictRect.left), StringWidth(windTitle) ),
  336.             2*(pictRect.bottom - pictRect.top)
  337.                          );
  338.     LongToQDRect(&itsMainPane->frame, &paneRect);
  339.     CenterRects(&pictRect, &paneRect);
  340.  
  341.     /* Set the initial drawing of the PICT at the center of window:
  342.     **
  343.     ** Note that we scroll the pane UP in order to scroll the
  344.     ** panorama DOWN and vice-versa.  This is directly analogous to
  345.     ** clicking on the UP scroll arrow of a ScrollBar and seeing the
  346.     ** text scroll DOWN.
  347.     **
  348.     ** Note also that the picture will NOT be scrolled at all if we
  349.     ** had called SetScaled(true) above because in this instance the
  350.     ** offseting of the frame in CScrollPane::DoScroll equals the
  351.     ** offseting of the port's origin.  As a result, the picture's
  352.     ** topLeft point will still be at the topLeft of the port.         */
  353.     scrollPn->DoScroll(- (long) pictRect.left/pict->hScale,
  354.                        - (long) pictRect.top /pict->vScale);
  355.  
  356.  // ChangeSize destroys the prep work done by System 7:
  357.  // if ( !WINDResourceHasSystem7Field(itsWindow) )        {
  358.                 
  359.         itsWindow->SetModal(false);
  360.         // Gotta do this kludge because CenterWindow tests isModal
  361.         // AND the window's procID:
  362.         saveProcID = itsWindow->procID;
  363.         itsWindow->procID = 0;
  364.         gDecorator->CenterWindow(itsWindow);
  365.         itsWindow->procID = saveProcID;
  366.  // }
  367.     
  368. }    /* ISpiffyScroll */
  369.  
  370.  
  371.  
  372. void    CSpiffyGraphics::DisplaySpiffyScroll (void)        {
  373.  
  374.         LongPt            thePosition;
  375.         LongRect        theFrame;
  376.         PicHandle        thePICT;
  377.         Rect            pictRect;
  378.         long            DH, DV, finalTicks;
  379.         
  380.  
  381.     // Initial position, centered, is negative:
  382.     pict->GetPosition(&thePosition);
  383.     
  384.     itsWindow->GetFrame(&theFrame);
  385.     thePICT = pict->GetMacPicture();
  386.     pictRect = (**thePICT).picFrame;
  387.     DH = - (theFrame.right    - (pictRect.right  - pictRect.left))/pict->hScale;
  388.     DV = - (theFrame.bottom - (pictRect.bottom - pictRect.top ))/pict->vScale;
  389.     
  390.     itsWindow->Select();
  391.     itsMainPane->Prepare();
  392.     itsWindow->Update();        /* ... so the initially centered PICT gets drawn. */
  393.     Delay(45, &finalTicks);
  394.         
  395.     while (thePosition.h != 0)    {        /* Scroll to left edge. */
  396.         if (AnyKeyHasBeenPressed())        return;
  397.         if (MouseHasBeenClicked())        break;
  398.         pict->itsScrollPane->DoScroll(1, 0);
  399.         pict->GetPosition(&thePosition);
  400.         Delay(10, &finalTicks);
  401.     }
  402.  
  403.     while (thePosition.v != 0)    {        /* Scroll up to topLeft corner. */
  404.         if (AnyKeyHasBeenPressed())        return;
  405.         if (MouseHasBeenClicked())        break;
  406.         pict->itsScrollPane->DoScroll(0, 1);
  407.         pict->GetPosition(&thePosition);
  408.         Delay(10, &finalTicks);
  409.     }
  410.  
  411.     while (true)    /* ... and around and around she goes ... */    {
  412.  
  413.         while (thePosition.h > DH)  {        /* -> topRight */
  414.             if (AnyKeyHasBeenPressed())        return;
  415.             if (MouseHasBeenClicked())        break;
  416.             pict->itsScrollPane->DoScroll(-1, 0);
  417.             pict->GetPosition(&thePosition);
  418.             Delay(10, &finalTicks);
  419.         }
  420.         
  421.         while (thePosition.v > DV)  {        /* -> bottomRight */
  422.             if (AnyKeyHasBeenPressed())        return;
  423.             if (MouseHasBeenClicked())        break;
  424.             pict->itsScrollPane->DoScroll(0, -1);
  425.             pict->GetPosition(&thePosition);
  426.             Delay(10, &finalTicks);
  427.         }
  428.  
  429.         while (thePosition.h != 0)  {        /* -> bottomLeft */
  430.             if (AnyKeyHasBeenPressed())        return;
  431.             if (MouseHasBeenClicked())        break;
  432.             pict->itsScrollPane->DoScroll(1, 0);
  433.             pict->GetPosition(&thePosition);
  434.             Delay(10, &finalTicks);
  435.         }
  436.         
  437.         while (thePosition.v != 0)  {        /* -> topLeft again */
  438.             if (AnyKeyHasBeenPressed())        return;
  439.             if (MouseHasBeenClicked())        break;
  440.             pict->itsScrollPane->DoScroll(0, 1);
  441.             pict->GetPosition(&thePosition);
  442.             Delay(10, &finalTicks);
  443.         }
  444.         
  445.     }    /* while (true) */
  446.     
  447. }    /* DisplaySpiffyScroll */
  448.  
  449.  
  450.  
  451. void    CSpiffyGraphics::DisposeSpiffyScroll (void)        {
  452.  
  453.  
  454.     pict->Dispose();
  455.     
  456.     inherited::Dispose();
  457.     
  458. }    /* DisposeSpiffyScroll */
  459.  
  460.  
  461.  
  462. Boolean        AnyKeyHasBeenPressed (void)        {
  463.  
  464.         EventRecord        event;
  465.         
  466.         
  467.     return ( GetNextEvent(keyDownMask, &event) );
  468.     
  469. }    /* AnyKeyHasBeenPressed */
  470.  
  471.  
  472.  
  473. Boolean        MouseHasBeenClicked (void)        {
  474.  
  475.         EventRecord        event;
  476.         
  477.         
  478.     return ( GetNextEvent(mDownMask, &event) );
  479.     
  480. }    /* MouseHasBeenClicked */
  481.  
  482.  
  483.  
  484. void    CenterRects (Rect *srcRect, Rect *withinRect)    {
  485.  
  486.         short        srcW, srcH, tempX, tempY;
  487.  
  488.     
  489.     srcW = srcRect->right - srcRect->left;
  490.     // within width - source width:
  491.     tempX = withinRect->right - withinRect->left - srcW;
  492.     srcRect->left = withinRect->left + tempX/2;
  493.     srcRect->right = srcRect->left + srcW;
  494.     ;
  495.     srcH = srcRect->bottom - srcRect->top;
  496.     // within height - source height:
  497.     tempY = withinRect->bottom - withinRect->top - srcH;                            
  498.     srcRect->top = withinRect->top + tempY/2;
  499.     srcRect->bottom = srcRect->top + srcH;
  500.     
  501. }    /* CenterRects */
  502.  
  503.  
  504.  
  505. Boolean        aDAisUp (WindowPeek macWindow)        {
  506.  
  507.         #define    MenuListLoc        0xA1C
  508.  
  509.         typedef    struct    rMenuRec    {
  510.             MenuHandle    menuOH;
  511.             short        menuLeft;            /* Left edge of Menu. */
  512.         }    rMenuRec;
  513.  
  514.         typedef    struct    hMenuRec    {
  515.             MenuHandle    menuHOH;
  516.             short        reserved;
  517.         }    hMenuRec;
  518.  
  519.         typedef    struct    MenuList    {
  520.             short            lastMenu;        /* Offset to last regular MenuHandle. */
  521.             short            lastRight;        /* Right edge of last Menu's title. */
  522.             short            mbResID;
  523.             rMenuRec        rMenu[];
  524.         //    The following fields are also present:
  525.         //
  526.         //    short            lastHMenu;    --    Offset from here to last
  527.         //                                    hierarchical Menu.
  528.         //    PixMapHandle    menuTitleSave;
  529.         //    hMenuRec        hMenu[];    --    When my daMenu routine is called,
  530.         //                                    there are NO hierarchical Menus.
  531.         }    MenuList, *MenuListPtr, **MenuListHdl;
  532.  
  533.         MenuListHdl        MLHdl = (MenuListHdl) (* (long*)MenuListLoc );
  534.         short            nbrMenusX6, menuCounter, theMenuID;
  535.         
  536.  
  537.     if ( macWindow && macWindow->windowKind < 0 ) /* IsSystemWindow */ return (true);
  538.  
  539.     else    /* Look for DA MENU, with NO window */        {
  540.         nbrMenusX6 = (*MLHdl)->lastMenu;
  541.         menuCounter = (nbrMenusX6 / 6) - 1;
  542.  
  543.         while (menuCounter >= 0)
  544.         {
  545.             theMenuID = (* (*MLHdl)->rMenu[menuCounter].menuOH )->menuID;
  546.         //    Watch out !!! with System 7 ...
  547.         //    ... the Help Menu (kHMHelpMenuID = -16490) &
  548.         //    ... the Application Menu (ID = ???)
  549.             if ((theMenuID < 0) && (theMenuID >= -16384))    break;
  550.             --menuCounter;
  551.         }    /* scanning the MenuBar */
  552.  
  553.         //    I could have used
  554.         //            daMenu = theMenuID < 0;
  555.         //    because I KNOW my app has menus.  However, to make this routine
  556.         //    applicable to ANY app, what if ANY app had zip menus and there
  557.         //    were no DA menus, I would have to initialize with
  558.         //            theMenuID = 0;
  559.         //    putting an extra statement in a time-critical "doPeriodic" loop.
  560.         
  561.         return (menuCounter >= 0);
  562.     }
  563.     
  564. }    /* aDAisUp */
  565.  
  566.  
  567.  
  568. /* ===============
  569.    Play it, Sam !! 
  570.    =============== */
  571.  
  572.  void PlaySound (Str255 mySound)    {
  573.  
  574.         Handle            sndHandle;
  575.         OSErr            discardError;
  576.  
  577.  
  578.     if (TrapAvailable(_SndPlay))
  579.     {
  580.         sndHandle = GetNamedResource('snd ', mySound);
  581.         if (sndHandle)
  582.         {
  583.             discardError = SndPlay (nil, sndHandle, false);
  584.             ReleaseResource(sndHandle);
  585.         }
  586.     }    /* _SndPlay is implemented */
  587.  
  588. }    /* PlaySound */
  589.  
  590.  
  591.  
  592. long    GetStripAddressMask (void)    {
  593. /* Adapted from Macintosh Tech Note #213 */
  594.  
  595.         long    gLo3Bytes        = 0x00FFFFFF;
  596.      /* #define    _StripAddress = 0xA055; */
  597.  
  598.         long    localBiggee;
  599.  
  600.  
  601.     if (TrapAvailable(_StripAddress))
  602.     {
  603.         localBiggee = 0xFFFFFFFF;
  604.         return((long)StripAddress((Ptr)&localBiggee));
  605.     }
  606.     else    return(gLo3Bytes);
  607.  
  608. }    /* GetStripAddressMask */
  609.  
  610.  
  611.  
  612. Ptr    QuickStrip (long *myPtr)    {
  613.  
  614.     return((Ptr)((long)myPtr & gStripAddressMask));
  615.  
  616. }    /* QuickStrip */
  617.  
  618.  
  619.  
  620. Boolean        WINDResourceHasSystem7Field (CWindow *theWindow)    {
  621.  
  622.         Boolean        extraField;
  623.         short        windType, index, rType;
  624.         Byte        wTitleLength;
  625.         Handle        rHdl;                /* Handle to WIND resource template    */
  626.         
  627.         
  628.     if (!gSystem.hasHelpMgr)        extraField = false;
  629.     else
  630.     {
  631.         extraField = false;            // Assume NOT there !!
  632.             
  633.         windType = theWindow->procID;
  634.         ;
  635.         for (index = 1; index <= Count1Resources('WIND'); index++)
  636.         {
  637.             rHdl = Get1IndResource('WIND', index);
  638.             if (rHdl == nil)    continue;
  639.             
  640.             asm    {
  641.                 move.l    rHdl, a0
  642.                 move.l    (a0), a0
  643.                 move.w    8(a0), rType
  644.                 ; We don't care about the Title itself, ONLY its length !!
  645.                 ; Note also that the "title" addressed here is that
  646.                 ; in the 'WIND' resource which will be different than
  647.                 ; the actual title displayed IF you've called _SetWTitle
  648.                 ; somewhere along the line:
  649.                 move.b    18(a0), wTitleLength
  650.             }
  651.             // Compare window types:
  652.             if (windType == rType)    {
  653.                 /*
  654.                     oldType        |                newType
  655.                     -------        |                -------
  656.                 18 + 1 + len    |    a) odd  length:    18 + 1 + len + 2
  657.                                 |    b) even length:    18 + 1 + len + fill byte + 2
  658.                 */
  659.                 if ( GetHandleSize(rHdl) > 18 + 1 + wTitleLength + 1 )
  660.                     extraField = true;
  661.                 break;
  662.             }
  663.         }    /* end for-loop */
  664.             
  665.     }    // System 7.
  666.     
  667.     return (extraField);
  668.  
  669. }    /* WINDResourceHasSystem7Field */
  670.  
  671.  
  672.  
  673. GDHandle    GetMaxAreaDevice (Rect *globalRect)        {
  674. /* Find the greatest overlap device for the given global rectangle. */
  675.  
  676.         long        area, maxArea;
  677.         GDHandle    result, device;
  678.         Rect        intersection;
  679.  
  680.  
  681.     result = nil;
  682.     ;
  683.     maxArea = 0;
  684.     ;
  685.     device = GetDeviceList();
  686.  
  687.     while (device != nil)    {
  688.         if (TestDeviceAttribute(device, screenDevice))    {
  689.             if (TestDeviceAttribute(device, screenActive))    {
  690.  
  691.                 if (SectRect(globalRect, &((**device).gdRect), &intersection))    {
  692.  
  693.                     area = (long)(intersection.right - intersection.left) * 
  694.                            (long)(intersection.bottom - intersection.top);
  695.  
  696.                     if (area > maxArea)    {
  697.                         result = device;
  698.                         maxArea = area;
  699.                     }    /* if area > maxArea */
  700.  
  701.                 }    /* if SectRect ... */
  702.  
  703.             device = GetNextDevice(device);
  704.             }    /* screenActive */
  705.         }    /* screenDevice */
  706.     }    /* while */
  707.  
  708.     return (result);
  709.  
  710. }    /* GetMaxAreaDevice */
  711.  
  712.  
  713.  
  714.  
  715. /* end: "CmyMisc.c" */